<?php
/**
 * Created by PhpStorm.
 * User: hgq
 * Date: 16/6/24
 * Time: 下午1:23
 */
use yii\helpers\Url;
$web = Url::base();

?>
<script type="text/javascript" src="<?= $web ?>/js/jquery.tooltips.js"></script>
<script type="application/javascript">
    var extend_category_id='<?=$id?>';
    function asynCheckAll(){
        if($('[name="checkbox_is_hide"]:checked').length==$('[name="checkbox_is_hide"]').length){
            $('#cb_all').attr("checked",true);
        }else{
            $('#cb_all').removeAttr("checked");
        }
    }
    function getLevel2(){
        var data={};
        data.id=extend_category_id;
        data.code=$('#head_categoryV1').val();
        if(data.code==''){
            $('#head_categoryV2').html('');
            $('#head_categoryV3').html('');
            return;
        }
        var re=requestJson('get-next-level-goods-category',data);
        if(re.status==0){
            var html="<option value=''>--选择商品2级分类--</option>";
            $.each(re.data,function(i,item){
                html=html+"<option value='"+item.code+"'>"+item.name+"</option>";
            });
            $('#head_categoryV2').html(html);
        }else {
            alert(re.message);
        }
    }
    function getLevel3(){
        var data={};
        data.id=extend_category_id;
        data.code=$('#head_categoryV2').val();
        if(data.code==''){
            $('#head_categoryV3').html('');
            return;
        }
        var re=requestJson('get-next-level-goods-category',data);
        if(re.status==0){
            var html="<option value=''>--选择商品3级分类--</option>";
            $.each(re.data,function(i,item){
                html=html+"<option value='"+item.code+"'>"+item.name+"</option>";
            });
            $('#head_categoryV3').html(html);
        }else {
            alert(re.message);
        }
    }
    function filtergoods() {

        var code = $("#head_code").val();
        var name = $("#head_name").val();
        var brand = $("#head_brand").val();
        var is_hide = $("#head_is_hide").val();
        var categoryV1 = $("#head_categoryV1").val();
        var categoryV2 = $("#head_categoryV2").val();
        var categoryV3 = $("#head_categoryV3").val();
        var priceS = $("#head_priceS").val();
        var priceE = $("#head_priceE").val();
        var extend_category = $("#head_extend_category").val();
        var ncTagId = $("#head_ncTagId").val();

        var data = {};
        data.id = extend_category_id;
        data.code = code;
        data.name = name;
        data.brand = brand;
        data.selected = is_hide;
        data.categoryV1 = categoryV1;
        data.categoryV2 = categoryV2;
        data.categoryV3 = categoryV3;
        data.priceS = priceS;
        data.priceE = priceE;
        data.extend_category = extend_category;
        data.ncTagId = ncTagId;

        $("#body_table").html('');
        requestHtml('goods-extend-category-goods-table-view', data, true, function (responseHtml) {
            $("#body_table").html(responseHtml);
            tooltipsPreview();
        }, function () {
            $("#body_table").html('');
        });
    }
    function goodsIsIndexShowSet(me,goods_code,institution_code) {
        var checkedv= me.checked;
        var data = {};
        data.extend_category_id = extend_category_id;
        data.goods_code = goods_code;
        data.institution_code = institution_code;
        data.selected = checkedv ? 1 : 0;
        requestJson("goods-extend-category-goods-is-index-show-set", data,true,function(re){
            if (re.status == 0) {
                //   $("#hint_message").text('操作成功！');

            } else {
                $("#hint_message").text('操作失败！');
                $("#hintMessageModal").modal('show');
            }
        });


    }
    function goodsSelectdSet(me) {
        var checkedv= me.checked;
        var data = {};
        data.extend_category_id = extend_category_id;
        data.goods_code = $(me).siblings('[name="code"]').val();
        data.institution_code = $(me).siblings('[name="institution_code"]').val();
        data.selected = checkedv ? 1 : 0;
        requestJson("goods-extend-category-goods-set", data,true,function(re){
            if (re.status == 0) {
                //   $("#hint_message").text('操作成功！');
                var is_index_show_dom=$(me).parent().parent().find('[name="checkbox_is_index_show"]');
                if(checkedv==1){
                    is_index_show_dom.removeAttr('disabled');
                }else {
                    is_index_show_dom.attr('disabled','disabled');
                    is_index_show_dom.removeAttr('checked');
                }
            } else {
                $("#hint_message").text('操作失败！');
                $("#hintMessageModal").modal('show');
            }
        });


    }
    function goodsAllSelectSet(selected){
        var allCheck=$('[name="checkbox_is_hide"]');
        if(allCheck.length==0){
            alert('没有要操作的数据');
            return;
        }
        var msg='全选';
        if(selected==0){
            msg='全部取消';
        }
        if(confirm('是否执行'+msg+'操作？')==false){
            return;
        }
        //loading.show();

        var data = {};
        data.institution_code = $($(allCheck).get(0)).siblings('[name="institution_code"]').val();
        data.extend_category_id = extend_category_id;
        data.selected=selected;
        var goods_codes=[];
        $.each(allCheck,function(i,me){
            goods_codes.push( $(me).siblings('[name="code"]').val());
        });
        data.goods_codes =goods_codes;
        requestJson("goods-extend-category-goods-set-bat", data,true,function(re){
            if (re.status == 0) {
                //   $("#hint_message").text('操作成功！');
                filtergoods();
            } else {
                $("#hint_message").text('操作失败！');
                $("#hintMessageModal").modal('show');
            }
        });

    }


</script>

<!-- head filter-->

<div class="form-inline">
    <div class="pull-left" style=" margin-top: 5px">
        <div class="form-group">
            <label class="sr-only" for="exampleInputEmail2">可见状态</label>
            <select class="form-control popovers" style="width: 160px;" id="head_is_hide">
                <option value="">可见状态</option>
                <option value="1">已选择</option>
                <option value="0">未选择</option>
            </select>
        </div>
        <div class="form-group">
            <label class="sr-only" for="exampleInputEmail2">商品编码</label>
            <input type="text" class="form-control" id="head_code" placeholder="商品编码" value="">
        </div>
        <div class="form-group">
            <label class="sr-only" for="exampleInputPassword2">商品名称</label>
            <input type="text" class="form-control" id="head_name" placeholder="商品名称" value="">
        </div>
        <div class="form-group">
            <label class="sr-only" for="exampleInputPassword2">商品品牌</label>
            <input type="text" class="form-control" id="head_brand" placeholder="商品品牌" value="">
        </div>
        <div class="form-group">
            <label class="sr-only" for="exampleInputPassword2">商品分类(一级)</label>
            <select class="form-control" id="head_categoryV1" onchange="getLevel2()">
                <option value=''>--选择商品1级分类--</option>
                <?php
                    foreach($categoryV1 as $item){
                        echo "<option value='".$item['code']."'>".$item['name']."</option>";
                    }
                ?>
            </select>
        </div>
        <div class="form-group">
            <label class="sr-only" for="exampleInputPassword2">商品分类(二级)</label>
            <select class="form-control" id="head_categoryV2" onchange="getLevel3()">
                <option value=''>--选择商品2级分类--</option>
            </select>
        </div>
        <div class="form-group">
            <label class="sr-only" for="exampleInputPassword2">商品分类(三级)</label>
            <select class="form-control" id="head_categoryV3">
                <option value=''>--选择商品3级分类--</option>
            </select>
        </div>
        <div class="form-group">
            <label class="sr-only" for="exampleInputPassword2">商品扩展分类</label>
            <select class="form-control" id="head_extend_category">
                <option value=''>--筛掉其他扩展分类已选商品--</option>
                <?php
                foreach($extendCategoryType2 as $item){
                    if($id==$item['id']){
                        continue;
                    }
                    echo "<option value='".$item['id']."'>".$item['name']."</option>";
                }
                ?>
            </select>
        </div>
        <div class="form-group">
            <label class="sr-only" for="exampleInputPassword2">NC扩展分类</label>
            <select class="form-control" id="head_ncTagId">
                <option value=''>--选择NC扩展分类--</option>
                <?php
                foreach($NcTagList as $item){
                    echo "<option value='".$item['id']."'>".$item['name']."</option>";
                }
                ?>
            </select>
        </div>
        <div class="form-group">
            <label  for="exampleInputPassword2">价格区间</label>
            <input type="text" class="form-control"  id="head_priceS" placeholder="起始价格" value="">--
            <input type="text" class="form-control"  id="head_priceE" placeholder="截止价格" value="">
        </div>
        <button type="button" class="btn btn-primary" onclick="filtergoods()"><i class="fa fa-search"></i> 搜索
        </button>
    </div>
</div>
<!-- body table-->
<div id="body_table">
    <!--<div class="table-responsive">
        <table class="table table-bordered table-hover table-condensed" style=" margin-top: 5px">
            <thead class="nowrap">
            <tr>
                <th style="width:30%">商品编码</th>
                <th style="width:40%">商品名称</th>
                <th style="width:10%">商品品牌</th>
                <th style="width:10%">是否选择</th>
            </tr>
            </thead>
            <tbody>

            </tbody>
        </table>
    </div>-->
</div>

